package office.pdf.tabula;

import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.spire.pdf.FileFormat;
import com.spire.pdf.PdfDocument;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 描述
 *
 * @author: zhanglu
 * @date: 2023/7/28 14:56
 * @modify: 修改人信息, 修改内容 2023/7/28 14:56
 */
public class LuTest {

    public static void main(String[] args) {
//        PDFTableReader<Object> reader = PDFTableReader
//                .load(new File("/Users/zhanglu/Desktop/tmp/pdfbox/输变电工程质量检测工作手册2.pdf"), Object.class)
//                .describe(63, 1, 15)
//                .titleRowIndex(2);
//        List<Map<String, String>> maps = reader.doRead();
//        System.out.println(maps);

//        //加载示例SVG图片
//        PdfDocument doc = new PdfDocument();
//        doc.loadFromSvg("/Users/zhanglu/Downloads/下载.svg");
//        //保存为PDF文档
//        doc.saveToFile("/Users/zhanglu/Downloads/下载1.pdf", FileFormat.PDF);

        test01();
    }

    public static void test01(){
        String json = "/Users/zhanglu/Desktop/1.txt";
//        List<String> collect = JSONUtil.parseObj(FileUtil.readUtf8String(json)).getJSONArray("data").stream().filter(o -> {
//            JSONObject obj = (JSONObject) o;
////            String enterpriseName = obj.getStr("enterpriseName");
////            if (ObjectUtil.isEmpty(enterpriseName)) {
////                return false;
////            }
////            return enterpriseName.contains("福建");
//            return obj.getInt("materialsUpFlag") == 1 && obj.getInt("personnelStatus") == 3 && obj.getInt("enterpriseStatus") == 3 && obj.getInt("enterpriseStatus") == 3;
//        }).map(o -> ((JSONObject)o).getStr("id")).distinct().collect(Collectors.toList());
//
//
//
//        for (List<String> strings : Lists.partition(collect, 10)) {
//            String join = StrUtil.join(",", strings);
//            System.out.println(join);
//        }

        JSONArray data = JSONUtil.parseObj(FileUtil.readUtf8String(json)).getJSONArray("data");
        System.out.println("总数：" + data.size());
        List<Object> s1 = data.stream().filter(o -> {
            JSONObject obj = (JSONObject) o;
            return obj.getInt("personnelStatus") == 3 && obj.getInt("enterpriseStatus") == 3 && obj.getInt("qualificationsStatus") == 3 && obj.getInt("materialsUpFlag") == 1 && obj.getInt("status") == 2;
        }).collect(Collectors.toList());
        System.out.println("做完证书申请的：" + s1.size());
//        s1 = data.stream().filter(o -> {
//            JSONObject obj = (JSONObject) o;
//            return obj.getInt("personnelStatus") == 3 && obj.getInt("enterpriseStatus") == 3 && obj.getInt("qualificationsStatus") == 3 && obj.getInt("materialsUpFlag") == 1 && obj.getInt("status") == 1;
//        }).collect(Collectors.toList());
//        System.out.println("需要做证书申请的：" + s1.size());
//        s1 = data.stream().filter(o -> {
//            JSONObject obj = (JSONObject) o;
//            return obj.getInt("personnelStatus") == 3 && obj.getInt("enterpriseStatus") == 3 && obj.getInt("qualificationsStatus") == 3 && obj.getInt("materialsUpFlag") == 1 && obj.getInt("status") != 2;
//        }).collect(Collectors.toList());
//        System.out.println("可以做证书申请的但是status不对的：" + s1.size());
//        s1 = data.stream().filter(o -> {
//            JSONObject obj = (JSONObject) o;
//            return obj.getInt("personnelStatus") == 3 && obj.getInt("enterpriseStatus") == 3 && obj.getInt("qualificationsStatus") == 3 && obj.getInt("materialsUpFlag") == 0;
//        }).collect(Collectors.toList());
//        System.out.println("数据异常的：" + s1.size());
//        s1 = data.stream().filter(o -> {
//            JSONObject obj = (JSONObject) o;
//            return obj.getInt("personnelStatus") == 3 && obj.getInt("enterpriseStatus") == 3 && obj.getInt("qualificationsStatus") == 1 && obj.getInt("materialsUpFlag") == 1 && obj.getInt("status") != 2;
//        }).collect(Collectors.toList());
//        System.out.println("需要资质审核的：" + s1.size());
//        s1 = data.stream().filter(o -> {
//            JSONObject obj = (JSONObject) o;
//            return obj.getInt("personnelStatus") == 3 && obj.getInt("enterpriseStatus") == 3 && obj.getInt("qualificationsStatus") == 1 && obj.getInt("materialsUpFlag") == 0;
//        }).collect(Collectors.toList());
//        System.out.println("数据又异常的：" + s1.size());
//        s1 = data.stream().filter(o -> {
//            JSONObject obj = (JSONObject) o;
//            return obj.getInt("personnelStatus") == 3 && obj.getInt("enterpriseStatus") == 3 && obj.getInt("qualificationsStatus") == 1 && obj.getInt("materialsUpFlag") == 1 && obj.getInt("status") == 2;
//        }).collect(Collectors.toList());
//        System.out.println("需要检查status的：" + s1.size());
//        s1 = data.stream().filter(o -> {
//            JSONObject obj = (JSONObject) o;
//            return obj.getInt("status") == 2 && ObjectUtil.isNotEmpty(obj.getStr("upspNo"));
//        }).map(o -> ((JSONObject)o).getStr("id")).collect(Collectors.toList());
//        System.out.println("企业认证理应完全通过的：" + s1.size());
//        s1 = data.stream().filter(o -> {
//            JSONObject obj = (JSONObject) o;
//            return obj.getInt("personnelStatus") == 3 && obj.getInt("enterpriseStatus") == 3 && obj.getInt("qualificationsStatus") == 3 && obj.getInt("materialsUpFlag") == 1 && obj.getInt("status") == 2;
//        }).collect(Collectors.toList());
//        System.out.println("企业认证用户角度完全通过的：" + s1.size());
//        s1 = data.stream().filter(o -> {
//            JSONObject obj = (JSONObject) o;
//            return obj.getInt("personnelStatus") == 3 && obj.getInt("enterpriseStatus") == 3 && obj.getInt("qualificationsStatus") == 3 && obj.getInt("materialsUpFlag") == 1 && obj.getInt("status") == 2 && ObjectUtil.isNotEmpty(obj.getStr("upspNo"));
//        }).collect(Collectors.toList());
//        System.out.println("企业认证完全通过的且数据完全正常的：" + s1.size());
//        s1 = data.stream().filter(o -> {
//            JSONObject obj = (JSONObject) o;
//            return (obj.getInt("personnelStatus") != 3 || obj.getInt("enterpriseStatus") != 3 || (obj.getInt("qualificationsStatus") != 3 && obj.getInt("qualificationsStatus") != 1)) && obj.getInt("materialsUpFlag") == 1;
//        }).collect(Collectors.toList());
//        System.out.println("数据有问题的：" + s1.size());
//        System.out.println("数据有问题的：" + JSONUtil.toJsonStr(s1));
//
//        s1 = data.stream().filter(o -> {
//            JSONObject obj = (JSONObject) o;
//            return obj.getInt("status") == 1 && obj.getInt("personnelStatus") == 0 && obj.getInt("enterpriseStatus") == 0;
//        }).map(o -> ((JSONObject)o).getStr("id")).collect(Collectors.toList());
//        System.out.println("重复数据数量：" + s1.size());
//        System.out.println("重复数据：" + StrUtil.join(",", s1));
//
//        s1 = data.stream().filter(o -> {
//            JSONObject obj = (JSONObject) o;
//            return ObjectUtil.isEmpty(obj.getStr("idCard")) && (obj.getInt("status") == 1 || obj.getInt("status") == 3);
//        }).collect(Collectors.toList());
//        System.out.println("数据是空的：" + s1.size());
//        System.out.println("数据是空的：" + StrUtil.join(",", s1));
//
//        s1 = data.stream().filter(o -> {
//            JSONObject obj = (JSONObject) o;
//            return obj.getInt("personnelStatus") == 2;
//        }).map(o -> {
//            JSONObject obj = (JSONObject) o;
//            Map<String, Object> params = new HashMap<>();
//            params.put("企业名称", obj.getStr("enterpriseName"));
//            params.put("经办人", obj.getStr("operatorName"));
//            params.put("审核结果", obj.getInt("personnelStatus"));
//            params.put("审核消息", obj.getStr("personnelStatusMsg"));
//            return params;
//        }).collect(Collectors.toList());
//        System.out.println("个人审核退回的：" + s1.size());
//        System.out.println("个人审核退回的：：" + StrUtil.join(",", s1));
//        ExcelWriter writer = ExcelUtil.getWriter();
//        writer.write(s1);
//        writer.flush(FileUtil.file("/Users/zhanglu/Desktop/个人审核退回.xlsx"));
//        s1 = data.stream().filter(o -> {
//            JSONObject obj = (JSONObject) o;
//            return obj.getInt("enterpriseStatus") == 2;
//        }).map(o -> {
//            JSONObject obj = (JSONObject) o;
//            Map<String, Object> params = new HashMap<>();
//            params.put("企业名称", obj.getStr("enterpriseName"));
//            params.put("审核结果", obj.getInt("enterpriseStatus"));
//            params.put("审核消息", obj.getStr("enterpriseStatusMsg"));
//            return params;
//        }).collect(Collectors.toList());
//        System.out.println("企业审核退回的：" + s1.size());
//        System.out.println("企业审核退回的：：" + StrUtil.join(",", s1));
//        writer = ExcelUtil.getWriter();
//        writer.write(s1);
//        writer.flush(FileUtil.file("/Users/zhanglu/Desktop/企业审核退回.xlsx"));

        s1 = data.stream().filter(o -> {
            JSONObject obj = (JSONObject) o;
            return obj.getInt("personnelStatus") == 2 || obj.getInt("enterpriseStatus") == 2 || obj.getInt("qualificationsStatus") == 2;
        }).map(o -> {
            JSONObject obj = (JSONObject) o;
            Map<String, Object> params = new HashMap<>();
//            params.put("个人信息审核退回原因", obj.getStr("personnelStatusMsg"));
//            params.put("企业信息审核退回原因", obj.getStr("enterpriseStatusMsg"));
            params.put("资质材料审核退回原因", obj.getStr("qualificationsStatusMsg"));
            return params;
        }).distinct().collect(Collectors.toList());
        ExcelWriter writer = ExcelUtil.getWriter();
        writer.write(s1);
        writer.flush(FileUtil.file("/Users/zhanglu/Desktop/企业认证退回原因01.xlsx"));
//        List<Map<String, Object>> collect = JSONUtil.parseObj(FileUtil.readUtf8String(json)).getJSONArray("data").stream().filter(o -> {
//            JSONObject obj = (JSONObject) o;
//            return ObjectUtil.isEmpty(obj.getStr("idCard")) || ObjectUtil.isEmpty(obj.getStr("socialCreditCode")) || ObjectUtil.isEmpty(obj.getStr("enterLegalUser")) || ObjectUtil.isEmpty(obj.getStr("enterpriseName"));
//        }).map(o -> {
//            JSONObject obj = (JSONObject) o;
//            Map<String, Object> params = new HashMap<>();
//            params.put("序号", obj.getStr("id"));
//            params.put("企业名称", obj.getStr("enterpriseName"));
//            params.put("统一社会信用代码", obj.getStr("socialCreditCode"));
//            params.put("法人姓名", obj.getStr("enterLegalUser"));
//            params.put("法人身份证号", obj.getStr("idCard"));
//            params.put("总状态", obj.getInt("status"));
//            params.put("个人注册审核", obj.getInt("personnelStatus"));
//            params.put("企业注册审核", obj.getInt("enterpriseStatus"));
//            params.put("企业资质审核", obj.getInt("qualificationsStatus"));
//            return params;
//        }).collect(Collectors.toList());
//        System.out.println(JSONUtil.toJsonStr(collect));
//        ExcelWriter writer = ExcelUtil.getWriter();
//        writer.write(collect);
//        writer.flush(FileUtil.file("/Users/zhanglu/Desktop/企业基础信息丢失.xlsx"));
    }

    /*
        {"code":"res010203", "id": "ff1eb1b85199439fbd945d27b2160f2b"}
        {"code":"res01", "id": "024f2e96fec14e7d8e4f7fda381396a5"}
        {"code":"cxdb", "id": "024f2e96fec14e7d8e4f7fda381396a5"}

{"code":"cxtymfycsj","grzc_cfbs":"返回data为null！请检查输入输出结果，完整数据","qyzc_cfbs":"返回data为null！请检查输入输出结果，完整数据","status":"1","id":"ff1eb1b85199439fbd945d27b2160f2b"}
{"code":"cxtymfycsj","grzc_cfbs":"返回data为null！请检查输入输出结果，完整数据","qyzc_cfbs":"返回data为null！请检查输入输出结果，完整数据","id":"df127b5e05df428c85bb70c7fba88860"}


{"code":"qyzztj", "personnelStatus": "3", "enterpriseStatus": "3", "qualificationsStatus": "2"}

{"code":"cxdb"}

{"code":"cxdb", "personnelStatus": "3", "enterpriseStatus": "3", "qualificationsStatus": "3", "status": "2"}

{"code":"cxdb", "personnelStatus": "3", "enterpriseStatus": "3"}
{"code":"cxtymfycsj","grzc_cfbs":"返回data为null！请检查输入输出结果，完整数据","qyzc_cfbs":"返回data为null！请检查输入输出结果，完整数据","name":"福建"}

{"code":"cxtymfycsj","grzc_cfbs":"请检查输入输出结果，完整数据","qyzc_cfbs":"请检查输入输出结果，完整数据","name":"福建经典工程咨询有限公司"}

系统繁忙，请稍后重试：返回data为null！请检查输入输出结果，完整数据


    {"code":"res01", "id": "5d53544ddb1a4dc5999a8cdf23349b36"}
      {"code":"cxdb", "id": "29f45fe4020d481aac7d388dc216ccbf"}
    {"code":"sub01", "qualificationsStatus": "2", "id": "a773654d65734e92ba9cf84f48220f9c"}

{"code":"sub01", "qualificationsStatus": "0", "personnelStatus": 3, "enterpriseStatus": 3}

{"code":"grzctj", "id": "439b44a4cea04c54a162ab129925bb5b"}

{"code":"qyzctj", "id": "439b44a4cea04c54a162ab129925bb5b"}


{"code":"cxdb", "id": "024f2e96fec14e7d8e4f7fda381396a5"}

{"code":"sub01", "ids": "b1438aa5a2a6410e9e4b57806a813c89"}


{"code":"qyzctj", "ids": "b8c13d32e152404c98bb33ee47268674"}

{"code":"grzctj", "ids": "e29b7eef6b4a488bb8991818642944e6"}



2e5cfc6b36804ba28e12bd27294ff0ae

{"id":"fbe37ee6b2f14f4bb644731725f38e43", "personnelStatus": 3, "personnelStatusMsg": ""}


 {"code":"sub01", "id": "853dc58034564d009b11f7a1506f0c8d"}

{"id":"b8c13d32e152404c98bb33ee47268674","idCard":"310105196301182862"}



{"id":"f12ccaccac4944ae9ce2d90f8d5fd1b3","status":1, "enterpriseStatus": 0}

张金明，35260119750927151X，9135080073361984D

{"id":"f70d55fee7954b24bf4500edfe9dbc6c","socialCreditCode":"91330600792093427B", "enterLegalUser": "王洪海", "idCard": "330126197208250058"}
91330600792093427B
王洪海
330126197208250058


{"id":"45e56e854711475cbdcb0f6f6fcab181","socialCreditCode":"91350800733619847D"}


衢州光明电力工程有限公司：企业法人身份证：330126197311190014    法人姓名 ：叶青
统一社会信用代码：913308007046042086

{"id":"d5b348add80a4ceaac5f1061a8e6bd0c","enterpriseStatus":2, "enterpriseStatusMsg": "法人身份证缺少盖章，法人身份证如果使用的是复印件加盖公章，请对整个复印件进行拍照，上传两次即可"}

{"id":"42c1fdd4a78d487a9b61a55a1c11e494","personnelStatus":2, "personnelStatusMsg": "个人注册黑白复印件的要求公章信息完整字迹清晰可见，对整个复印件拍照，上传两次"}

{"id":"fd642a788ede4ad391c82d68354be7da","personnelStatus":2, "personnelStatusMsg": "个人注册黑白复印件的要求公章信息完整字迹清晰可见，对整个复印件拍照，上传两次","enterpriseStatus":2, "enterpriseStatusMsg": "身份证反面无公章信息，请将复印件整张拍照，上传两次即可"}

{"id":"10d7734adf50466e81853f01a3061920","enterpriseName": "", }

###问题数据，误删
{"extra":null,"traceId":null,"success":true,"data":{"createrId":"EC3D682391B30C97E0430100007F78C9","updaterId":"","createTime":"2023-10-10 01:14:18","updateTime":"2023-10-18 20:25:53","provinceCode":null,"id":"10d7734adf50466e81853f01a3061920","enterpriseId":"055C3B07020F648DE065000000000001","enterpriseName":"舟山启明电力设计院有限公司监理分公司","socialCreditCode":"913309003553700514","enterLegalUser":"虞晗波","idCard":"330903197611285217","legalReprMobile":"","idcardFileId":"de25d88bf4de49379f12542ad2724157","idcardBackFileId":"df3463d90fb44b058f8e7e2cfa6247e0","applyFileId":"a6b8efd3456b4335849a5d416ebe64b9","proxyFileId":"66e0a70f1c624d83b0edf0f77cc03f2b","signatureFileId":null,"licenseFileId":"f428d2e917f848d9b541c37540921284","authenticDate":null,"materialsUpFlag":1,"serialNo":"1697467877914471617","upspNo":"20020f032310121484803d96ec243807bb92","status":2,"createrUnitId":null,"createrName":"舟山启明电力设计院有限公司","enterpriseType":1,"deployEnv":"OUT","operatorIdcardFontId":"e844005aab964927a6d8a1398179146f","operatorIdcardBackId":"0f98a649d46b4f8baadbea162e8b0579","operatorName":"张晓英","operatorIdcard":"130132198303292867","operatorPhone":"13857203438","operatorCertSerialNo":null,"personnelStatus":3,"personnelStatusMsg":null,"enterpriseStatus":3,"enterpriseStatusMsg":null,"qualificationsStatus":3,"qualificationsStatusMsg":""},"code":"200","message":"操作成功"}


{
        "id": "10d7734adf50466e81853f01a3061920",
        "enterpriseName": "舟山启明电力设计院有限公司",
        "socialCreditCode": "",
        "enterLegalUser": "",
        "idCard": "",
        "legalReprMobile": "",
        "idcardFileId": "",
        "idcardBackFileId": "",
        "applyFileId": "",
        "proxyFileId": "",
        "licenseFileId": "",
        "materialsUpFlag": 0,
        "serialNo": "",
        "upspNo": "",
        "status": 0,
        "operatorIdcardFontId": "",
        "operatorIdcardBackId": "",
        "operatorName": "",
        "operatorIdcard": "",
        "operatorPhone": "",
        "personnelStatus": 0,
        "enterpriseStatus": 0,
        "qualificationsStatus": 0,
        "qualificationsStatusMsg": ""
    },

{"code":"sub01", "id": "29641d554951412db7a34228c7b0507e"}
{"code":"cxdb", "id": "56dde090dce24ebd92d3b092ef50cdf7"}





退回
国网福建电力有限公司福州供电公司    e09b785eb41e461e8da75a944d05c934  个人、企业存在重复数据
国网福建电力有限公司厦门供电公司    fd642a788ede4ad391c82d68354be7da  个人、企业存在重复数据
国网福建电力有限公司龙岩供电公司    07c2e23b839f4951b5ba49debf25add2  个人、企业存在重复数据
国网福建电力有限公司三明供电公司    e29b7eef6b4a488bb8991818642944e6  个人、企业存在重复数据
福建亿兴电力设计院有限公司         e554b706c5144942acd8e47838684c5e  企业存在重复数据
三明亿源申力工程建设有限公司       4214ae4fe6484693893645191f77df29  企业存在重复数据

{"code":"cxdb", "id": "024f2e96fec14e7d8e4f7fda381396a5"}

{"code":"res02", "id": "024f2e96fec14e7d8e4f7fda381396a5"}

{"code":"res02", "id": "3c750a7c493941b5a67cce7aa1380294"}

{"code":"res010203", "id": "fd642a788ede4ad391c82d68354be7da"}
{"code":"res010203", "id": "07c2e23b839f4951b5ba49debf25add2"}
{"code":"res010203", "id": "e29b7eef6b4a488bb8991818642944e6"}
{"code":"res010203", "id": "e554b706c5144942acd8e47838684c5e"}
{"code":"res010203", "id": "4214ae4fe6484693893645191f77df29"}
{"code":"cxdb", "ids": "e09b785eb41e461e8da75a944d05c934,fd642a788ede4ad391c82d68354be7da,07c2e23b839f4951b5ba49debf25add2,e29b7eef6b4a488bb8991818642944e6,e554b706c5144942acd8e47838684c5e,4214ae4fe6484693893645191f77df29"}

{"code":"grzctj", "ids": "e09b785eb41e461e8da75a944d05c934,fd642a788ede4ad391c82d68354be7da,07c2e23b839f4951b5ba49debf25add2,e29b7eef6b4a488bb8991818642944e6"}
{"code":"qyzctj", "ids": "e09b785eb41e461e8da75a944d05c934,fd642a788ede4ad391c82d68354be7da,07c2e23b839f4951b5ba49debf25add2,e29b7eef6b4a488bb8991818642944e6,e554b706c5144942acd8e47838684c5e,4214ae4fe6484693893645191f77df29"}

{"code":"qyzctj", "id": "024f2e96fec14e7d8e4f7fda381396a5"}


国网福建电力有限公司福州供电公司      个人注册审核中；企业注册审核中
国网福建电力有限公司厦门供电公司      个人注册审核中；企业注册审核中
国网福建电力有限公司龙岩供电公司      个人注册审核中；企业注册审核中
国网福建电力有限公司三明供电公司      个人注册审核中；企业注册审核中
福建亿兴电力设计院有限公司           个人注册审核成功；企业注册审核中
三明亿源申力工程建设有限公司         个人注册审核成功；企业注册审核中


资质审核
福建闽能咨询有限公言 22e0a1f371ca47ff8242ad18a6f08675
福建省莆田市电力工程有限公司 d8d31982c28f46d0b68f93874f54b185
厦门电力工程集团有限公司  6c6491ff6a25455cade9b4919d38c941
{"code":"sub01", "id": "22e0a1f371ca47ff8242ad18a6f08675"}
{"code":"sub01", "id": "d8d31982c28f46d0b68f93874f54b185"}
{"code":"sub01", "id": "6c6491ff6a25455cade9b4919d38c941"}

{"code":"cxdb", "ids": "22e0a1f371ca47ff8242ad18a6f08675,d8d31982c28f46d0b68f93874f54b185,6c6491ff6a25455cade9b4919d38c941"}



















































     */

}
